<!DOCTYPE html>
<html>
<head>
    <script src="/assets/jquery/jquery-3.1.1.min.js"></script>
    <script src="/assets/layui-2.9.18/layui.js"></script>
    <link rel="stylesheet" href="/assets/layui-2.9.18/css/layui.css">
    <link rel="stylesheet" href="/assets/layui-2.9.18/css/admin.css">
    <script src="/assets/september/common.js"></script>
    <script src="/assets/september/htmlBuilder.js"></script>
    <script src="/assets/september/search.js"></script>
    <link rel="stylesheet" href="/assets/pages/list.css">
    <link rel="stylesheet" href="/assets/pages/form.css?1">
    <style>
        .layui-form-label {
            width: 200px !important;
        }
    </style>
</head>
<body>

<div class="layui-form" style="padding: 20px 20px 0 20px;">
    <form id="form" class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">host</label>
            <div class="layui-input-inline">
                <input type="text" name="host" class="layui-input" lay-verify="required"/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">port</label>
            <div class="layui-input-inline">
                <input type="number" name="port" class="layui-input" value="6666"  lay-verify="required"/>
            </div>
        </div>



    </form>
    <div class="layer-footer" style="float:right;margin-bottom:10px;">
        <input class="layui-btn layui-btn-normal wid-200px" style="margin-right: 150px" lay-submit lay-filter="submit_button"
               value="保存">
    </div>
</div>


<script>
    layui.config({
        base: '../../../assets/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'table'], function () {
        let form = layui.form;
        form.on("submit", function (data) {
            var data = data.field;
            if (data['typeRadio'] == 'camera') {
                data['port'] = ''
                data['type'] = ''
            }
            layer.confirm("确定保存吗？", function () {
                sajax({
                    url: "/led/doAddLed",
                    type: "post",
                    data: data,
                    dataType: 'json',
                    success: function (res) {
                        layer.msg('保存成功', {shade: [0.1, '#fff'], time: 1600});
                        closeWindowAndRefreshParent();
                    }
                })
            });
        });

        form.on('select(ledName)', function (data) {
            var val = data.value;
            if (val == 'nova') {
                $('input[name="port"]').val("5000")
            }
            if (val == 'shizhan') {
                $('input[name="port"]').val("6666")
            }
            if (val == 'lingxin') {
                $('input[name="port"]').val("10000")
            }
            if (val == 'yangbang') {
                $('input[name="port"]').val("")
            }
            if (val == 'yangbang-B6') {
                $('input[name="port"]').val("5005")
            }
        })

        form.on('radio(typeRadio)', function (data) {
            if (data.value == 'camera') {
                $('.led').css('display', 'none')
            } else {
                $('.led').css('display', 'block')
            }
        })
    });

    function checkType(event) {
        console.log($(event).attr('title'))
    }
</script>

</body>
</html>
